package com.ruoyi.park.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.park.domain.BuiPark;
import com.ruoyi.park.service.IBuiParkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 园区Controller
 *
 * @author cjie
 * @date 2021-07-20
 */
@Api(tags = " 园区")
@RestController
@RequestMapping("/buiPark")
public class BuiParkController extends BaseController {
    @Autowired
    private IBuiParkService buiParkService;


    /**
     * 服务调用
     * @param parkId
     * @return
     */
    @GetMapping(value = "getPark/{parkId}")
    public R<BuiPark> getParkById(@PathVariable("parkId") String parkId){
        return R.ok(buiParkService.selectBuiParkById(parkId));
    }


    /**
     * 查询园区列表
     */
    @ApiOperation(value="查询园区列表", notes="查询园区列表")
    @PreAuthorize(hasPermi = "park:buiPark:list")
    @GetMapping("/list")
    public TableDataInfo list(BuiPark buiPark) {
        startPage();
        List<BuiPark> list = buiParkService.selectBuiParkList(buiPark);
        return getDataTable(list);
    }

    /**
     * 查询园区、楼栋树
     * @return
     */
    @ApiOperation(value="查询园区、楼栋树", notes="查询园区、楼栋树")
    @GetMapping("/listTree")
    public AjaxResult parkTree(){
        return AjaxResult.success(buiParkService.selectParkTree());
    }


    /**
     * 导出园区列表
     */
    @ApiOperation(value="导出园区列表", notes="导出园区列表")
    @PreAuthorize(hasPermi = "park:buiPark:export")
    @Log(title = "园区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuiPark buiPark) throws IOException {
        List<BuiPark> list = buiParkService.selectBuiParkList(buiPark);
        ExcelUtil<BuiPark> util = new ExcelUtil<BuiPark>(BuiPark.class);
        util.exportExcel(response, list, "园区数据");
    }
    /**
     * 获取园区详细信息
     */
    @ApiOperation(value="获取园区详细信息", notes="获取园区详细信息")
    @PreAuthorize(hasPermi = "park:buiPark:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(buiParkService.selectBuiParkById(id));
    }

    /**
     * 新增园区
     */
    @ApiOperation(value="新增园区", notes="新增园区")
    @PreAuthorize(hasPermi = "park:buiPark:add")
    @Log(title = "园区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuiPark buiPark) {
        return buiParkService.insertBuiPark(buiPark);
    }

    /**
     * 修改园区
     */
    @ApiOperation(value="修改园区", notes="修改园区")
    @PreAuthorize(hasPermi = "park:buiPark:edit")
    @Log(title = "园区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuiPark buiPark) {
        return buiParkService.updateBuiPark(buiPark);
    }

    /**
     * 删除园区
     */
    @ApiOperation(value="删除园区", notes="删除园区")
    @ApiImplicitParam(name = "ids", value = "园区ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "park:buiPark:remove")
    @Log(title = "园区", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(buiParkService.deleteBuiParkByIds(ids));
    }
}
